var evaluateuserDAO = require('../models/evaluateuserDAO')
var evaluateusercontroller =  {
    //插入评论
    insertEvaluate:function(req,res){
        // var time = req.body.time
        var content = req.body.content
        var grade = req.body.grade
        // var tradeID = req.body.tradeID
        // var orderID = req.body.orderID
        evaluateuserDAO.insertEvaluate({content:content,grade:grade},function(err,results){
            if(err){
                console.log(err)
                res.json({code:500,msg:'数据库出错，上传出错'})
            }else{
                res.json({code:200,data:results,msg:'上传成功!'})
            }
        })
    },
    delEvaluate:function(req,res){
        // var time = req.body.time
        var evaluateID = req.query.evaluateID
        evaluateuserDAO.delEvaluate(evaluateID,function(err,results){
            if(err){
                console.log(err)
                res.json({code:500,msg:'数据库出错，删除失败'})
            }else{
                res.json({code:200,data:results,msg:'删除成功!'})
            }
        })
    },
    selEvaluate:function(req,res){
        // var time = req.body.time
        evaluateuserDAO.selEvaluate(function(err,results){
            if(err){
                console.log(err)
                res.json({code:500,msg:'数据库出错，查询失败'})
            }else{
                res.json({code:200,data:results,msg:'查询成功!'})
            }
        })
    },
    selOneEvaluate:function(req,res){
        let tradeID = req.query.tradeID
        evaluateuserDAO.selOneEvaluate(tradeID,function(err,results){
            if(err){
                console.log(err)
                res.json({code:500,msg:'数据库出错，查询失败'})
            }else{
                res.json({code:200,data:results,msg:'查询成功!'})
            }
        })
    },
    insertbackevaluate:function(req,res){
        var replycontent = req.body.replycontent
        var userID = req.body.userID
        var evaluateID = req.body.evaluateID
        evaluateuserDAO.insertbackevaluate({replycontent:replycontent,userID:userID,evaluateID:evaluateID},function(err,results){
            if(err){
                console.log(err)
                res.json({code:500,msg:'数据库出错，评论失败'})
            }else{
                res.json({code:200,data:results,msg:'评论成功!'})
            }
        })
    },
    delbackevaluate:function(req,res){
        var replyID = req.query.replyID
        evaluateuserDAO.delbackevaluate(replyID,function(err,results){
            if(err){
                console.log(err)
                res.json({code:500,msg:'数据库出错，删除失败'})
            }else{
                res.json({code:200,data:results,msg:'删除成功!'})
            }
        })
    },
    selbackevaluate:function(req,res){
        var evaluateID = req.query.evaluateID
        evaluateuserDAO.selbackevaluate(evaluateID,function(err,results){
            console.log(results)
            if(err){
                console.log(err)
                res.json({code:500,msg:'数据库出错，查询失败'})
            }else{
                res.json({code:200,data:results,msg:'查询成功!'})
            }
        })
    },
}
module.exports = evaluateusercontroller